package com.example.demo.result;


import com.example.demo.constant.ErrorCode;
import lombok.Data;


import java.io.Serializable;

/**
 * 统一返回结果
 */
@Data
public class Result<T> implements Serializable {

    private Integer code;//状态码

    private String msg;//提示信息

    private T data;//数据

    public static <T> Result<T> success(T data) {
        Result result = new Result();
        result.code=1000;
        result.data=data;
        return result;
    }

    public static <T> Result<T> success(){
        Result result=new Result();
        result.code=1000;
        return  result;
    }

    public static <T> Result<T> error(String msg){
        Result result=new Result();
        result.code=1001;
        result.msg=msg;
        return result;
    }

    public static <T> Result<T> error(ErrorCode errorCode){
        Result result=new Result();
        result.code=errorCode.getCode();
        result.msg=errorCode.getDescription();
        return result;
    }

}
